(function (){
    var SceneManger = window.SceneManager = function (){

        this.sceneNumber=1;
        game.bg = new Background();
        game.bird = new Bird();


        //logo的y值
        this.logoY = -48;
        //button_play的y值
        this.button_playX = game.canvas.width / 2 - 58;
        this.button_playY = game.canvas.height;


        //添加监听
        this.bindEvent();

    }

    SceneManger.prototype.update=function (){
        switch(this.sceneNumber) {
            case 1 :
                //让logo进行移动
                this.logoY += 10;
                if (this.logoY > 120) {
                    this.logoY = 120;
                }
                //让按钮移动
                this.button_playY -= 16;
                if (this.button_playY < 360) {
                    this.button_playY = 360;
                }
                break;
            case 2:
                //小鸟扑打翅膀
                game.bird.wing();
                break;
        }

    }

    SceneManager.prototype.render = function() {
        switch (this.sceneNumber) {
            case 1:
                game.bg.render();
                game.bird.render();
                //渲染小鸟
                game.bird.render();
                game.bird.x = game.canvas.width / 2;
                game.bird.y = 260;

                //画logo
                game.ctx.drawImage(game.R["logo"],game.canvas.width / 2 - 89,this.logoY);
                //画按钮
                game.ctx.drawImage(game.R["button_play"],this.button_playX,this.button_playY);
                break;
            case 2:
                game.bg.render();
                game.bird.render();
                //渲染小鸟
                game.bird.render();
                game.bird.x = game.canvas.width / 2;
                game.bird.y = 260;
                break;

        }
    }

    //进入某个场景要做的事情
    SceneManager.prototype.enter = function(number) {
        this.sceneNumber = number;
        switch(this.sceneNumber) {
            case 1 :
                //进入1号场景这一瞬间要做的事情
                this.logoY = -48;
                // this.button_playY = game.canvas.height;
                break;
            case 2:
                game.bird.y = 150;
                //tutorial的透明度0~1
                this.tutorialOpacity = 1;
                this.tutorialOpacityIsDown = true;
                break;
        }
    }

    //添加监听
    SceneManager.prototype.bindEvent = function(){
        var self = this;
        game.canvas.onclick = function(event){
            clickHandler(event.clientX , event.clientY);
        };

        function clickHandler(mousex,mousey){
            //点击的时候判断当前是第几个场景
            switch(self.sceneNumber){
                case 1 :
                    //进入1号场景这一瞬间要做的事情
                    if(mousex > self.button_playX && mousex < self.button_playX + 116 && mousey > self.button_playY && mousey < self.button_playY + 70){
                        //说明用户点击到了按钮上
                        self.enter(2);	//去2号场景
                    }
                    break;
                case 2 :
                    self.enter(3);	//去3号场景
                    break;
                case 3 :
                    game.bird.fly();
                    break;
                case 5 :
                    self.enter(1);
                    break;
            }
        }
    }
    })();